﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Windows.Controls.Ribbon;
using System.Collections.ObjectModel;

namespace DentistApplication
{
    /// <summary>
    /// Interaction logic for PatientFileWindow.xaml
    /// </summary>
    public partial class PatientFileWindow : RibbonWindow
    {
        public PatientFileWindow()
        {
            InitializeComponent();

            //Make some multiline text in labels
            bt_file.Content = "Kartoteka pacjenta";
            bt_applast.Content = "Ostatnie wizyty pacjenta";
            bt_appnew.Content = "Umówione wizyty pacjenta";

            _patientCollection.Clear();
            List<Patient> lp = PatientsHandler.getAllPatients();
            lp.ForEach(x => _patientCollection.Add(x));
          
        }

        ObservableCollection<Patient> _patientCollection = new ObservableCollection<Patient>();

        public ObservableCollection<Patient> patientCollection
        { get { return _patientCollection; } }

        #region RIBBON - Search for Patient

        private void list_patientsSearch_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
            if (list_patientsSearch.SelectedIndex != -1)
            {
                ribTAB_showData.IsSelected = true;
                la_nameLastname.Content = "pacjent: " + _patientCollection[list_patientsSearch.SelectedIndex].firstname + " " + _patientCollection[list_patientsSearch.SelectedIndex].lastname;
                la_patientId.Content = "Kartoteka nr: " + _patientCollection[list_patientsSearch.SelectedIndex].id;
            }
        }

       
        private void box_searchPatient_TextChanged(object sender, TextChangedEventArgs e)
        {
            int minLen = 0;
            string name = box_SearchPatName.Text;
            string lastname = box_SearchPatLastName.Text;
            string pesel = box_other.Text;

            if (name.Length > minLen || lastname.Length > minLen || pesel.Length > minLen)
            {
                _patientCollection.Clear();
                List<Patient> lp = PatientsHandler.searchForPatients(name, lastname, pesel);
                lp.ForEach(x => _patientCollection.Add(x));

            }
        }
       

        #endregion


        private void bt_file_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PatientFile pf = new PatientFile(_patientCollection[list_patientsSearch.SelectedIndex].id);
                pf.Show();
                this.Close();
            }
            catch { }
        }

        private void bt_applast_Click(object sender, RoutedEventArgs e)
        {
           try
            {
              
               new PF_LasVisitsWindow(_patientCollection[list_patientsSearch.SelectedIndex].id, "Ostatnie wizyty pacjenta", true).Show(); 
           }
            catch { }
        }

        private void bt_appnew_Click(object sender, RoutedEventArgs e)
        {
            try
            {
              
                new PF_LasVisitsWindow(_patientCollection[list_patientsSearch.SelectedIndex].id, "Umówione wizyty pacjenta", false).Show();
            }
            catch { }
        }

    }
}
